﻿using AutoMapper;
using B.S.Warehouse.Domain;
using B.S.Warehouse.ErrorCord;
using B.S.Warehouse.Read.Api.Application.Command.AllocateCommand;
using MediatR;
using SqlSugar;

namespace B.S.Warehouse.Read.Api.Application.Handelr.AllocateHandler
{
    public class FTAllocateHandler : IRequestHandler<FTAllocateCommand, ApiResult<List<Allocate>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public FTAllocateHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }
        public async Task<ApiResult<List<Allocate>>> Handle(FTAllocateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Allocate>> result = new ApiResult<List<Allocate>>();
            result.Code = ApiEnum.显示成功;
            result.MAG = ApiEnum.显示成功.ToString();

            var list = await db.Queryable<Allocate>().Where(x => x.IsDel == false && x.AllocateId == request.AllocateId).ToListAsync();
            result.data = list;
            return await Task.FromResult(result);
        }
    }
}
